package nc.bs.caa.plugin;

import java.util.List;

import nc.bs.framework.common.NCLocator;
import nc.bs.trade.business.HYPubBO;
import nc.itf.capub.datamanager.IDataHandling;
import nc.itf.capub.datamanager.SyncDataTaskRtn;
import nc.itf.uap.IUAPQueryBS;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.vo.capub.basevo.ClientEnvVO;
import nc.vo.capub.warning.DataSubVO;
import nc.vo.capub.warning.WarningconfVO;
import nc.vo.pub.BusinessException;

@SuppressWarnings("unchecked")
public abstract class AbstractDataHandling implements IDataHandling {
	private ClientEnvVO clientEnv;

	public void init() {
		// TODO
	}

	public AbstractDataHandling(ClientEnvVO clientEnv) {
		this.clientEnv = clientEnv;
		init();
	}

	public ClientEnvVO getClientEnv() {
		return clientEnv;
	}

	public abstract SyncDataTaskRtn dataHandling() throws BusinessException;

	public Boolean isPluginSuccess(String handledate, String plugincode)
			throws BusinessException {
		StringBuilder sql = new StringBuilder();
		sql.append("handledate='");
		sql.append(handledate).append("' and busiplugin='");
		sql.append(plugincode).append("'");
		DataSubVO[] subs = (DataSubVO[]) new HYPubBO().queryByCondition(
				DataSubVO.class, sql.toString());
		if (subs == null || subs.length == 0) {
			return Boolean.FALSE;
		}
		DataSubVO sub = subs[0];
		return sub.getIssuccess() == null ? Boolean.FALSE : sub.getIssuccess()
				.booleanValue();
	}

	public List<WarningconfVO> getPluginList(int plugintype)
			throws BusinessException {
		StringBuilder sql = new StringBuilder();
		sql.append("SELECT * FROM CAA_WARNING_CONFIG ");
		sql.append("WHERE isnull(dr,0)=0 AND plugintype= ").append(plugintype)
				.append(" ");
		sql.append("ORDER BY priodegree");
		IUAPQueryBS query = (IUAPQueryBS) NCLocator.getInstance().lookup(
				IUAPQueryBS.class.getName());
		List<WarningconfVO> list = (List<WarningconfVO>) query.executeQuery(
				sql.toString(), new BeanListProcessor(WarningconfVO.class));
		return list;
	}
}